package com.liu.queue;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * 如果要添加新的消息类型处理
 * 需要创建消息类,继承Message,可以什么内容都不写
 * 在MessageTypeEnum添加对应消息类型
 * 在main()方法内添加对应的Handler,Handler即对对应消息的处理器,在Handler(请求消息类型)处理器内会调用Storage的内存存储和持久化
 * <p>
 * 在MessageTypeEnum内添加对应的消息类型(byte)
 * <p>
 * <p>
 * 整体来说处理流程不需要管,只需要添加对应的处理类,以及消息类型
 */
public class Server {
    public static void main(String[] args) {
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        NioEventLoopGroup eventExecutors = new NioEventLoopGroup(1);
        serverBootstrap.group(eventExecutors);
        serverBootstrap.channel(NioServerSocketChannel.class);
        serverBootstrap.childHandler(new TcpServerInitializer());
        try {
            Channel pushChannel = serverBootstrap.bind(9111).sync().channel();
            Channel pullChannel = serverBootstrap.bind(9112).sync().channel();
            pushChannel.closeFuture().sync();
            pullChannel.closeFuture().sync();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            eventExecutors.shutdownGracefully();
        }
    }

}
